﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using RG.Common.Provider;
using NHibernate;
using log4net;

namespace RealtorGuide.DAO
{
   
    public class RGProvider : DAOProvider<RGProvider>
    {
        protected override string connectionConfig
        {
            get
            {
#if Release
                return "RG.Release";
#else
                return "RG.Debug";
#endif
            }
        }

        public RGProvider()
        {
            mappingAssembly = Assembly.GetExecutingAssembly();
            configResourceName = "RG.DAO.cfg.xml";
#if SHOW_SQL
            showSQL = true;
#endif
        }

        public override void CheckBaseConfig(ISession session)
        {
//            var bc = session.Get<S_Base_Const>(0);
//#if Beta
//            const string BaseVersion = "BETA";
//#elif DEBUG
//            const string BaseVersion = "DEBUG";
//#else
//            const string BaseVersion = "Release";
//#endif
//            if (bc.Version != BaseVersion)
//                throw new Exception(String.Format("Версия базы '{0}' не совпадает с версией программы '{1}'", bc.Version, BaseVersion));
//
//            if (log.IsInfoEnabled)
//                log.Info(String.Format("Provider created from {0}", BaseVersion));

        }
        
        private readonly ILog log = LogManager.GetLogger(typeof(RGProvider));
    }

    public class RGTransactionAttribute : ProviderAttribute
    {
        public override IDAOProvider GetProvider()
        {
            return new RGProvider();
        }
    }
}
